package 三种实现方式;

class MyRunnable implements Runnable {
    int count = 0;
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println(Thread.currentThread().getName() + ": " + (count++));
        }
    }
}

public class RunnableExample {
    public static void main(String[] args) {
        MyRunnable myRunnable = new MyRunnable();

        // 将MyRunnable实例作为参数传递给Thread构造函数
        Thread thread1 = new Thread(myRunnable, "MyThread-1"); // 可以指定线程名
        Thread thread2 = new Thread(myRunnable, "MyThread-2");

        thread1.start();
        thread2.start();

    }
}
